package zjh.msg.servelt;

import zjh.msg.dao.MsgDao;
import zjh.msg.entity.vo.MsgVo;
import zjh.msg.utils.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/listMsg")
public class ListMsgServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String pageNoStr = req.getParameter("pageNo");
        String pageSizeStr = req.getParameter("pageSize");
        int pageNo = pageNoStr == null ? 1 : Integer.parseInt(pageNoStr);
        int pageSize = pageSizeStr == null ? 10 : Integer.parseInt(pageSizeStr);
//        业务层
        MsgDao msgDao = new MsgDao();
        Page<MsgVo> msgVoPage = msgDao.listMsgPage(pageNo, pageSize);
        req.setAttribute("msgVoPage", msgVoPage);
        req.getRequestDispatcher("/pages/msg.jsp").forward(req, resp);
    }
}
